<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="../../pub/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>菜单管理</title>
<%@include file="../../pub/resource.jsp"%>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/zTreeStyle/zTreeStyle.css" />
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery.ztree.core-3.5.min.js"></script>
<style type="text/css">
body {
	padding-bottom: 40px;
}

.sidebar-nav {
	padding: 9px 0;
}

@media ( max-width : 980px) {
	/* Enable use of floated navbar text */
	.navbar-text.pull-right {
		float: none;
		padding-left: 5px;
		padding-right: 5px;
	}
}
</style>
<SCRIPT type="text/javascript">
<!--
	var setting = {
		callback : {
			onClick : zTreeOnClick
		}
	};

	var zNodes = ${json};

	$(document).ready(function() {
		$.fn.zTree.init($("#treeDemo"), setting, zNodes);
		$("#updateSelMenu").click(function() {
			currentWin.$.dialog({
				id : "id1",
				content : "你确定要进行更新操作吗？",
				lock : true,
				icon : "warning",
				path : rootPath+"/css",
				ok:function(){
					var id = trim($("#selId").val());
					var name = trim($("#selMenu").val());
					var url = trim($("#selUrl").val());
					var isNew = $(":radio[name='isNew']:checked").val();
					var isShow = $(":radio[name='isShow']:checked").val();
					if (id == "") {
						alertWin("请选择要修改的菜单！", "warning");
						return false;
					}
					if (name == "") {
						alertWin("请输入菜单名称！", "warning");
						return false;
					}
					$.ajax({
						url : "update.do",
						type : "post",
						dataType : "text",
						data : {
							id : id,
							name : name,
							url : url,
							isNew : isNew,
							isShow : isShow
						},
						success : function(data) {
							if (data == "success") {
								alertWin("更新成功！", "succeed");
								window.location = window.location.href;
							}
						}
					});
				},
				okVal:"更新",
				cancel:true,
				cancelVal:"取消"
			});
		});
		$("#addSelMenu").click(function() {
			var id = trim($("#selId").val());
			var name = trim($("#addMenu").val());
			var url = trim($("#addUrl").val());
			var isNew = $(":radio[name='isNew']:checked").val();
			var isShow = $(":radio[name='isShow']:checked").val();
			if (id == "") {
				alertWin("请选择上级的菜单！", "warning");
				return false;
			}
			if (name == "") {
				alertWin("请输入菜单名称！", "warning");
				return false;
			}
			$.ajax({
				url : "add.do",
				type : "post",
				dataType : "text",
				data : {
					parentId : id,
					name : name,
					url : url,
					isNew : isNew,
					isShow : isShow
				},
				success : function(data) {
					if (data == "success") {
						alertWin("添加成功！", "succeed");
						window.location = window.location.href;
					}
				}
			});
		});
		$("#delSelMenu").click(function(){
			currentWin.$.dialog({
				id : "id1",
				content : "你确定要进行删除操作吗？",
				lock : true,
				icon : "warning",
				path : rootPath+"/css",
				ok:function(){
					var id = trim($("#selId").val());
					if (id == "") {
						alertWin("请选择要修改的菜单！", "warning");
						return false;
					}
					$.ajax({
						url : "del.do",
						type : "post",
						dataType : "text",
						data : {
							id : id,
						},
						success : function(data) {
							if (data == "success") {
								alertWin("删除成功！", "succeed");
								window.location = window.location.href;
							}
						}
					});
				},
				okVal:"确定",
				cancel:true,
				cancelVal:"取消"
			});
		});
	});

	function zTreeOnClick(event, treeId, treeNode) {
		$("#selMenu").val(treeNode.name);
		$("#selId").val(treeNode.id);
		$("#selUrl").val(treeNode.menuUrl == "null" ? "" : treeNode.menuUrl);
		$(":radio[name='isNew']").removeAttr("checked");
		$(":radio[name='isNew']").each(function(index, element) {
			if ($(this).val() == treeNode.isNew) {
				$(this).attr("checked", "checked");
			}
		});
		$(":radio[name='isShow']").removeAttr("checked");
		$(":radio[name='isShow']").each(function(index, element) {
			if ($(this).val() == treeNode.isShow) {
				$(this).attr("checked", "checked");
			}
		});
		var parent=treeNode.getParentNode();
		if (parent!=null&&parent.id!=1) {
			$("#addSelMenu").attr("disabled", "disabled");
		} else {
			$("#addSelMenu").removeAttr("disabled");
		}
		if(treeNode.id==1){
			$("#delSelMenu").attr("disabled", "disabled");
		}else{
			$("#delSelMenu").removeAttr("disabled");
		}
	}
//-->
</SCRIPT>
</head>
<body>
	<div
		style="width: 300px; min-height: 600px; float: left; text-align: center; padding: 10px 0px 0px 20px;">
		<ul id="treeDemo" class="ztree"></ul>
	</div>
	<div
		style="float: left; border-left: 2px dashed #C7BEB5; text-align: left; width: 600px; min-height: 600px;">
		<table width="99%" border="0" cellspacing="0" cellpadding="0"
			class="table table-bordered table-hover definewidth m10">
			<tr>
				<td style="text-align: right;">当前选择菜单：</td>
				<td style="text-align: left;"><input type="text" name="selMenu"
					id="selMenu" placeholder="当前选择菜单" class="abc input-default" /> <input
					type="hidden" name="selId" id="selId" /></td>
			</tr>
			<tr>
				<td style="text-align: right;">当前选择菜单URL：</td>
				<td style="text-align: left;"><input type="text" name="selUrl"
					id="selUrl" placeholder="当前选择菜单URL" class="abc input-default" /></td>
			</tr>
			<tr>
				<td style="text-align: right;">添加子菜单：</td>
				<td style="text-align: left;"><input type="text" name="addMenu"
					id="addMenu" placeholder="要添加的子菜单名称" class="abc input-default"></td>
			</tr>
			<tr>
				<td style="text-align: right;">添加子菜单URL：</td>
				<td style="text-align: left;"><input type="text" name="addUrl"
					id="addUrl" placeholder="要添加的子菜单名称URL" class="abc input-default"></td>
			</tr>
			<tr style="display: none;">
				<td style="text-align: right;">打开方式：</td>
				<td style="text-align: left;"><input type="radio" id="isNew"
					name="isNew" value="1" />新窗口 <input type="radio" id="isNew"
					name="isNew" value="0" checked="checked" />当前窗口</td>
			</tr>
			<tr>
				<td style="text-align: right;">是否显示：</td>
				<td style="text-align: left;"><input type="radio" id="isShow"
					name="isShow" value="1" checked="checked" />显示 <input type="radio"
					id="isShow" name="isShow" value="0" />隐藏</td>
			</tr>
			<tr>
				<td colspan="2">
				<shiro:hasPermission name="菜单管理:删除">
				<input type="button" value="删除当前选择菜单" id="delSelMenu" name="delSelMenu" class="btn btn-danger" />
				</shiro:hasPermission>
				<shiro:hasPermission name="菜单管理:修改">
				&nbsp;&nbsp;<input type="button" value="修改当前选择菜单" id="updateSelMenu" name="updateSelMenu" class="btn btn-warning" />
				</shiro:hasPermission>
				<shiro:hasPermission name="菜单管理:添加">
				&nbsp;&nbsp;<input type="button" value="添加子菜单" id="addSelMenu" name="addSelMenu" class="btn btn-success" />
				</shiro:hasPermission>
				</td>
			</tr>
		</table>
	</div>
</body>
</html>